#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a) cin >> x;
  int limit = 1024;
  vector<vector<int>> dp(limit, vector<int>(n, -1));
  for (int i = 1; i < limit; i ++) {
    for (int j = n - 1; j >= 0; j --) {
      if (a[j] == i) dp[i][j] = j + 1;
      if (dp[i][j] == -1) continue;
      if (dp[i][j] == n) continue;
      if (dp[i][dp[i][j]] == -1) continue;
      dp[i+1][j] = dp[i][dp[i][j]];
    }
  }
  vector<int> linear(n + 1, INT_MAX);
  linear[0] = 0;
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < limit; j ++) {
      if (dp[j][i] == -1) continue;
      linear[dp[j][i]] = min(linear[dp[j][i]], linear[i] + 1);
    }
  }
  cout << linear[n] << endl;
}